﻿using System;
using System.Reflection;
using Caliburn;
using Caliburn.Modules;
using Caliburn.Services;

namespace NServiceBus.Management.Shell.Application
{
    public class RootFolderModuleLocator : FolderBasedModuleLocator
    {
        public RootFolderModuleLocator()
            : base("", false)
        {
        }

        protected override void LocateModules(Assembly assembly)
        {
            var manager = DI.Resolve<IModuleManager>();

            foreach (Type type in assembly.GetTypes())
            {
                if (!type.IsInterface && !type.IsAbstract && !type.Equals(typeof(Caliburn.Modules.Module)) && typeof(IModule).IsAssignableFrom(type))
                {
                    OnModuleFound(manager.CreateModule(type));
                }
            }
        }
    }
}
